home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / WINDOWS / DIRECT3D.ZIP / D3DMACS.H < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-13  |  5.4 KB  |  141 lines

  1. /*
  2.  *  Copyright (C) 1995, 1996 Microsoft Corporation. All Rights Reserved.
  3.  */
  4.  
  5. #ifndef __D3DMACS_H__
  6. #define __D3DMACS_H__
  7.  
  8. #undef RELEASE
  9.  
  10. #ifndef __cplusplus
  11. #define MAKE_MATRIX(lpDev, handle, data) \
  12.     if (lpDev->lpVtbl->CreateMatrix(lpDev, &handle) != D3D_OK) \
  13.         return FALSE; \
  14.     if (lpDev->lpVtbl->SetMatrix(lpDev, handle, &data) != D3D_OK) \
  15.         return FALSE
  16. #define RELEASE(x) if (x != NULL) {x->lpVtbl->Release(x); x = NULL;}
  17. #endif
  18.  
  19. #ifdef __cplusplus
  20. #define MAKE_MATRIX(lpDev, handle, data) \
  21.     if (lpDev->CreateMatrix(&handle) != D3D_OK) \
  22.         return FALSE; \
  23.     if (lpDev->SetMatrix(handle, &data) != D3D_OK) \
  24.         return FALSE
  25. #define RELEASE(x) if (x != NULL) {x->Release(); x = NULL;}
  26. #endif
  27.  
  28. #define PUTD3DINSTRUCTION(op, sz, cnt, ptr) \
  29.     ((LPD3DINSTRUCTION) ptr)->bOpcode = op; \
  30.     ((LPD3DINSTRUCTION) ptr)->bSize = sz; \
  31.     ((LPD3DINSTRUCTION) ptr)->wCount = cnt; \
  32.     ptr = (void *)(((LPD3DINSTRUCTION) ptr) + 1)
  33.  
  34. #define VERTEX_DATA(loc, cnt, ptr) \
  35.     if ((ptr) != (loc)) memcpy((ptr), (loc), sizeof(D3DVERTEX) * (cnt)); \
  36.     ptr = (void *)(((LPD3DVERTEX) (ptr)) + (cnt))
  37.  
  38. // OP_MATRIX_MULTIPLY size: 4 (sizeof D3DINSTRUCTION)
  39. #define OP_MATRIX_MULTIPLY(cnt, ptr) \
  40.     PUTD3DINSTRUCTION(D3DOP_MATRIXMULTIPLY, sizeof(D3DMATRIXMULTIPLY), cnt, ptr)
  41.  
  42. // MATRIX_MULTIPLY_DATA size: 12 (sizeof MATRIXMULTIPLY)
  43. #define MATRIX_MULTIPLY_DATA(src1, src2, dest, ptr) \
  44.     ((LPD3DMATRIXMULTIPLY) ptr)->hSrcMatrix1 = src1; \
  45.     ((LPD3DMATRIXMULTIPLY) ptr)->hSrcMatrix2 = src2; \
  46.     ((LPD3DMATRIXMULTIPLY) ptr)->hDestMatrix = dest; \
  47.     ptr = (void *)(((LPD3DMATRIXMULTIPLY) ptr) + 1)
  48.  
  49. // OP_STATE_LIGHT size: 4 (sizeof D3DINSTRUCTION)
  50. #define OP_STATE_LIGHT(cnt, ptr) \
  51.     PUTD3DINSTRUCTION(D3DOP_STATELIGHT, sizeof(D3DSTATE), cnt, ptr)
  52.  
  53. // OP_STATE_TRANSFORM size: 4 (sizeof D3DINSTRUCTION)
  54. #define OP_STATE_TRANSFORM(cnt, ptr) \
  55.     PUTD3DINSTRUCTION(D3DOP_STATETRANSFORM, sizeof(D3DSTATE), cnt, ptr)
  56.  
  57. // OP_STATE_RENDER size: 4 (sizeof D3DINSTRUCTION)
  58. #define OP_STATE_RENDER(cnt, ptr) \
  59.     PUTD3DINSTRUCTION(D3DOP_STATERENDER, sizeof(D3DSTATE), cnt, ptr)
  60.  
  61. // STATE_DATA size: 8 (sizeof D3DSTATE)
  62. #define STATE_DATA(type, arg, ptr) \
  63.     ((LPD3DSTATE) ptr)->drstRenderStateType = (D3DRENDERSTATETYPE)type; \
  64.     ((LPD3DSTATE) ptr)->dwArg[0] = arg; \
  65.     ptr = (void *)(((LPD3DSTATE) ptr) + 1)
  66.  
  67. // OP_PROCESS_VERTICES size: 4 (sizeof D3DINSTRUCTION)
  68. #define OP_PROCESS_VERTICES(cnt, ptr) \
  69.     PUTD3DINSTRUCTION(D3DOP_PROCESSVERTICES, sizeof(D3DPROCESSVERTICES), cnt, ptr)
  70.  
  71. // PROCESSVERTICES_DATA size: 16 (sizeof D3DPROCESSVERTICES)
  72. #define PROCESSVERTICES_DATA(flgs, strt, cnt, ptr) \
  73.     ((LPD3DPROCESSVERTICES) ptr)->dwFlags = flgs; \
  74.     ((LPD3DPROCESSVERTICES) ptr)->wStart = strt; \
  75.     ((LPD3DPROCESSVERTICES) ptr)->wDest = strt; \
  76.     ((LPD3DPROCESSVERTICES) ptr)->dwCount = cnt; \
  77.     ((LPD3DPROCESSVERTICES) ptr)->dwReserved = 0; \
  78.     ptr = (void *)(((LPD3DPROCESSVERTICES) ptr) + 1)
  79.  
  80. // OP_TRIANGLE_LIST size: 4 (sizeof D3DINSTRUCTION)
  81. #define OP_TRIANGLE_LIST(cnt, ptr) \
  82.     PUTD3DINSTRUCTION(D3DOP_TRIANGLE, sizeof(D3DTRIANGLE), cnt, ptr)
  83.  
  84. #define TRIANGLE_LIST_DATA(loc, count, ptr) \
  85.     if ((ptr) != (loc)) memcpy((ptr), (loc), sizeof(D3DTRIANGLE) * (count)); \
  86.     ptr = (void *)(((LPD3DTRIANGLE) (ptr)) + (count))
  87.  
  88. // OP_LINE_LIST size: 4 (sizeof D3DINSTRUCTION)
  89. #define OP_LINE_LIST(cnt, ptr) \
  90.     PUTD3DINSTRUCTION(D3DOP_LINE, sizeof(D3DLINE), cnt, ptr)
  91.  
  92. #define LINE_LIST_DATA(loc, count, ptr) \
  93.     if ((ptr) != (loc)) memcpy((ptr), (loc), sizeof(D3DLINE) * (count)); \
  94.     ptr = (void *)(((LPD3DLINE) (ptr)) + (count))
  95.  
  96. // OP_POINT_LIST size: 8 (sizeof D3DINSTRUCTION + sizeof D3DPOINT)
  97. #define OP_POINT_LIST(first, cnt, ptr) \
  98.     PUTD3DINSTRUCTION(D3DOP_POINT, sizeof(D3DPOINT), 1, ptr); \
  99.     ((LPD3DPOINT)(ptr))->wCount = cnt; \
  100.     ((LPD3DPOINT)(ptr))->wFirst = first; \
  101.     ptr = (void*)(((LPD3DPOINT)(ptr)) + 1)
  102.  
  103. // OP_SPAN_LIST size: 8 (sizeof D3DINSTRUCTION + sizeof D3DSPAN)
  104. #define OP_SPAN_LIST(first, cnt, ptr) \
  105.     PUTD3DINSTRUCTION(D3DOP_SPAN, sizeof(D3DSPAN), 1, ptr); \
  106.     ((LPD3DSPAN)(ptr))->wCount = cnt; \
  107.     ((LPD3DSPAN)(ptr))->wFirst = first; \
  108.     ptr = (void*)(((LPD3DSPAN)(ptr)) + 1)
  109.  
  110. // OP_BRANCH_FORWARD size: 18 (sizeof D3DINSTRUCTION + sizeof D3DBRANCH)
  111. #define OP_BRANCH_FORWARD(tmask, tvalue, tnegate, toffset, ptr) \
  112.     PUTD3DINSTRUCTION(D3DOP_BRANCHFORWARD, sizeof(D3DBRANCH), 1, ptr); \
  113.     ((LPD3DBRANCH) ptr)->dwMask = tmask; \
  114.     ((LPD3DBRANCH) ptr)->dwValue = tvalue; \
  115.     ((LPD3DBRANCH) ptr)->bNegate = tnegate; \
  116.     ((LPD3DBRANCH) ptr)->dwOffset = toffset; \
  117.     ptr = (void *)(((LPD3DBRANCH) (ptr)) + 1)
  118.  
  119. // OP_SET_STATUS size: 20 (sizeof D3DINSTRUCTION + sizeof D3DSTATUS)
  120. #define OP_SET_STATUS(flags, status, _x1, _y1, _x2, _y2, ptr) \
  121.     PUTD3DINSTRUCTION(D3DOP_SETSTATUS, sizeof(D3DSTATUS), 1, ptr); \
  122.     ((LPD3DSTATUS)(ptr))->dwFlags = flags; \
  123.     ((LPD3DSTATUS)(ptr))->dwStatus = status; \
  124.     ((LPD3DSTATUS)(ptr))->drExtent.x1 = _x1; \
  125.     ((LPD3DSTATUS)(ptr))->drExtent.y1 = _y1; \
  126.     ((LPD3DSTATUS)(ptr))->drExtent.x2 = _x2; \
  127.     ((LPD3DSTATUS)(ptr))->drExtent.y2 = _y2; \
  128.     ptr = (void *)(((LPD3DSTATUS) (ptr)) + 1)
  129.  
  130. // OP_NOP size: 4
  131. #define OP_NOP(ptr) \
  132.     PUTD3DINSTRUCTION(D3DOP_TRIANGLE, sizeof(D3DTRIANGLE), 0, ptr)
  133.  
  134. #define OP_EXIT(ptr) \
  135.     PUTD3DINSTRUCTION(D3DOP_EXIT, 0, 0, ptr)
  136.  
  137. #define QWORD_ALIGNED(ptr) \
  138.     !(0x00000007L & (ULONG)(ptr))
  139.  
  140. #endif // __D3DMACS_H__
  141.